package com.sc.nft.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.TempRequest;
import com.sc.nft.admin.request.UserCollectionRequest;
import com.sc.nft.admin.vo.TempUserCollectiblesOwnedVO;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.TempUserCollectiblesOwned;
import com.sc.nft.service.TempUserCollectiblesOwnedService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

import javax.validation.Valid;

/**
 * @author 朱梦晨
 * @Description: 用户拥有的藏品导出
 * @date 2024-07-25
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/temp/userCollectiblesOwned")
@Api(tags="用户拥有的藏品导出模块")
public class TempUserCollectiblesOwnedController {


    private final TempUserCollectiblesOwnedService tempUserCollectiblesOwnedService;


    @PostMapping(value = "/userCollectionExcel", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户拥有的藏品导出excel", notes = "用户拥有的藏品导出excel", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result tempUserCollectionExcel(@Valid @RequestBody UserCollectionRequest request){
        return Result.success(tempUserCollectiblesOwnedService.saveTempUserCollectiblesOwned(request.getFirstTitle(),request.getUserTel(),
                request.getStartTime(), request.getEndTime()));
    }

    @PostMapping(value = "/download", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户拥有的藏品下载", notes = "用户拥有的藏品下载", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<TempUserCollectiblesOwnedVO>> findTempUserCollectiblesOwnedList(@Valid @RequestBody TempRequest request){
        List<TempUserCollectiblesOwned> tempUserCollectiblesOwnedList = tempUserCollectiblesOwnedService.findTempUserCollectiblesOwnedList(request.getExportRecordsId());
        List<TempUserCollectiblesOwnedVO> tempUserCollectiblesOwnedVOS = BeanUtil.copyToList(tempUserCollectiblesOwnedList, TempUserCollectiblesOwnedVO.class);
        return Result.success(tempUserCollectiblesOwnedVOS);
    }

}
